package com.baidu.location;

import android.content.Context;
import android.content.IntentFilter;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Handler;
import java.lang.reflect.Field;
import java.lang.reflect.Method;

final class w
{
  private static String a = "baidu_location_service";
  private final long b = 3000L;
  private final long c = 3000L;
  private final long d = 5000L;
  private Context e;
  private Handler f = null;
  private WifiManager g = null;
  private y h = null;
  private x i = null;
  private z j = null;
  private long k = 0L;
  private long l = 0L;
  private boolean m = false;
  private Object n = null;
  private Method o = null;
  private boolean p = true;
  private boolean q = false;
  private boolean r = false;
  private boolean s = false;

  public w(Context paramContext, Handler paramHandler)
  {
    this.e = paramContext;
    this.f = paramHandler;
  }

  public final void a()
  {
    if (this.m == true)
      return;
    this.g = ((WifiManager)this.e.getSystemService("wifi"));
    this.h = new y(this, 0);
    try
    {
      this.e.registerReceiver(this.h, new IntentFilter("android.net.wifi.SCAN_RESULTS"));
      this.i = new x(this, 0);
      this.m = true;
      ak.e();
      try
      {
        Field localField = Class.forName("android.net.wifi.WifiManager").getDeclaredField("mService");
        if (localField != null)
          break label105;
        ak.e();
        return;
      }
      catch (Exception localException1)
      {
        localException1.printStackTrace();
        return;
      }
      label105: localException1.setAccessible(true);
      this.n = localException1.get(this.g);
      Class localClass = this.n.getClass();
      new StringBuilder("mserviceClass : ").append(localClass.getName());
      ak.e();
      this.o = localClass.getDeclaredMethod("startScan", new Class[] { Boolean.TYPE });
      if (this.o == null)
      {
        ak.e();
        return;
      }
      this.o.setAccessible(true);
      return;
    }
    catch (Exception localException2)
    {
    }
  }

  public final void b()
  {
    if (this.i != null)
      return;
    this.i = new x(this, 0);
  }

  public final void c()
  {
    if (!(this.m))
      return;
    try
    {
      this.e.unregisterReceiver(this.h);
      this.h = null;
      this.g = null;
      this.i = null;
      this.m = false;
      ak.e();
      return;
    }
    catch (Exception localException)
    {
    }
  }

  public final boolean d()
  {
    long l1 = System.currentTimeMillis();
    if (l1 - this.l <= 10000L)
      return false;
    this.l = l1;
    return e();
  }

  public final boolean e()
  {
    long l1;
    if (this.g == null);
    do
    {
      return false;
      l1 = System.currentTimeMillis();
    }
    while (l1 - this.k <= 3000L);
    try
    {
      if (this.g.isWifiEnabled())
        if (this.o != null)
        {
          Object localObject = this.n;
          if (localObject == null);
        }
      try
      {
        this.o.invoke(this.n, new Object[] { Boolean.valueOf(this.p) });
        this.k = l1;
        ak.e();
        return true;
      }
      catch (Exception localException1)
      {
        while (true)
        {
          while (true)
          {
            localException1.printStackTrace();
            this.g.startScan();
          }
          this.g.startScan();
        }
        this.k = 0L;
        return false;
      }
    }
    catch (Exception localException2)
    {
    }
    return false;
  }

  public final String f()
  {
    Object localObject = this.g.getConnectionInfo();
    if (localObject == null)
      return null;
    try
    {
      do
        localObject = ((WifiInfo)localObject).getBSSID();
      while (localObject == null);
      localObject = ((String)localObject).replace(":", "");
      return localObject;
    }
    catch (Exception localException)
    {
    }
    return ((String)null);
  }

  public final z g()
  {
    if ((((this.j == null) || (!(this.j.g())))) && (this.g != null))
      try
      {
        z localz = new z(this, this.g.getScanResults(), 0L);
        return localz;
      }
      catch (Exception localException)
      {
        return new z(this, null, 0L);
      }
    return this.j;
  }

  public final z h()
  {
    if ((((this.j == null) || (!(this.j.h())))) && (this.g != null))
      try
      {
        z localz = new z(this, this.g.getScanResults(), 0L);
        return localz;
      }
      catch (Exception localException)
      {
        return new z(this, null, 0L);
      }
    return this.j;
  }
}